#NoEnv  ; Recommended for performance and compatibility with future AutoHotkey releases.
#NoTrayIcon
#AllowSameLineComments
SetWorkingDir %A_ScriptDir%  ; Ensures a consistent starting directory.
SetBatchLines, -1
#include Gdip.ahk
#include DLB.ahk
book_T=Genesis|Exodus|Leviticus|Numbers|Deuteronomy|Joshua|Judges|Ruth|1 Samuel|2 Samuel|1 Kings|2 Kings|1 Chronicles|2 Chronicles|Ezra|Nehemiah|Esther|Job|Psalms|Proverbs|Ecclesiastes|Song of Songs|Isaiah|Jeremiah|Lamentations|Ezekiel|Daniel|Hosea|Joel|Amos|Obadiah|Jonah|Micah|Nahum|Habakkuk|Zephaniah|Haggai|Zechariah|Malachi|Matthew|Mark|Luke|John|Acts|Romans|1 Corinthians|2 Corinthians|Galatians|Ephesians|Philipians|Colossians|1 Thessalonians|2 Thessalonians|1 Timithoy|2 Timothy|Titus|Philemon|Hebrews|James|1 Peter|2 Peter|1 John|2 John|3 John|Jude|Revelation| |
loadfunc()
FileRead, listbox3Txt, Listboxtxt.txt
scripture_v = %sedit%
L = 1
I = button1
ButtonText = Go FullScreen


gogui1:
{
gui, 1: destroy
Gui, 1: Add, Button, x80 y190 w110 h20 g%I%, %ButtonText%
Gui, 1: Add, Button, x195 y190 w66 h20 gbutton3, Stored
Gui, 1: Add, Edit, x20 y65 w240 h120 -VScroll vsedit, %scripture_T%
Gui, 1: Add, DropDownList, x20 y25 w100 R10 Choose%L% altsubmit vbook_v, %book_T%
Gui, 1: Add, Edit, x160 y25 w100 h20 -vScroll +limit15 vchap_v, %chap_T%
Gui, 1: Add, Button, x15 y190 w40 h20 gwebscripture, online!
Gui, 1: Add, Text, x20 y10 w60 h15 , Book
Gui, 1: Add, Text, x160 y10 w70 h15 , Chapter:Verse
Gui, 1: Add, Text, x20 y50 w70 h15 , Scripture
Gui, 1: Show, AutoSize, FSS
}
return

webscripture:
GuiControl, 1:, button1, %buttonText%
guicontrolget, book_v,1:, book_v
guicontrolget, chap_v,1:, chap_v
L = %book_v%
chap_T = %chap_v%
IniRead, book_v, options.ini, Books, %L%
loop, parse, chap_v, :-
{
   if (A_index = 1)
      chap_v = %A_loopfield%
   if (A_index = 2)
      verse_n = %A_Loopfield%
   if (A_index = 3)
      if (a_loopfield <> "")
         verse_e = %A_Loopfield%
}      
stringlower, book_v, book_v
sedit := DLB( L, book_v, chap_v, verse_n)
guicontrol, 1:, sedit, %sedit%
scripture_T = %sedit%
return

save3:
{

   guicontrolget, sedit, 1:, sedit
   guicontrolget, book_v, 1:, book_v
   guicontrolget, chap_v, 1:, chap_v
   guicontrolget, listbox_v, 3:, listbox_v
   L = %book_v%
   scripture_T = %sedit%
   chap_T = %chap_v%
   IniRead, book_v, options.ini, Books, %L%
   
   
  if scripture_T =
   {
   msgbox, there was nothing to save.
   return
   }
   
   if listbox_v =
      listbox_v = 1
   
   IniWrite, %L%, options.ini, Save%listbox_v%, book
   iniwrite, %chap_v%, options.ini, Save%listbox_v%, Chap
   IniWrite, %sedit%, options.ini, Save%listbox_v%, script
   iniwrite, %book_v% %chap_v%, options.ini, Save%listbox_v%, saveslot
sleep, 800
 loadfunc()
 FileRead, listbox3Txt, Listboxtxt.txt
 Gui, 3: destroy
 D = 0
 gosub, button3
}
return

load3:
gui, 3: submit
{
   Loop{  ;load book loop
if A_index = 1
   B = book
if A_index = 2
   B = Chap
if A_index = 3
   B = Script
if A_index = 4
   break
iniread, Readline, options.ini, Save%listbox_v%, %B%

if B = book
   book_v = %Readline%
if B = chap
   chap_v = %Readline%
if B = Script 
    sedit = %Readline%
Gui, 3: destroy
 D = 0
 gosub, button3

}

guicontrol, 1:, book_v, %book_v%
guicontrol, 1:, chap_v, %chap_v%
guicontrol, 1:, sedit, %sedit%
L = %book_v%
chap_T = %chap_v%
scripture_T = %sedit%
gosub, gogui1
}
return

button3:
   if D = 1
   {
      Gui, 3: destroy
      D = 0
      return
   }
   {
Gui, 3: -SysMenu ; +Owner avoids a taskbar button.
Gui, 3: Add, listbox, AltSubmit h180 vlistbox_v, %listbox3Txt%
Gui, 3: Add, button, x10 y190 h20 w40 gsave3, Save
Gui, 3: Add, Button, x50 y190 h20 w40 gload3, Load
WinGetPos, x,y,w,h, FSS
x := x+w  
Gui , 3: Show, x%x% y%y% h216, Saved Scripture
D = 1
}
return

button2:
{
scripture_T = %sedit%
chap_T = %chap_v%
Gui, 2:destroy
Gdip_DeleteGraphics(G)
Gdip_Shutdown(ptoken)
I=button1
ButtonText = Go FullScreen
Guicontrol, 1:, button1, %buttonText%
gosub, gogui1
}
return

button1:
{
I=button2
ButtonText = Close FullScreen
GuiControl, 1:, button1, %buttonText%
guicontrolget, book_v,1:, book_v
guicontrolget, chap_v,1:, chap_v
L = %book_v%
chap_T = %chap_v%
IniRead, book_v, options.ini, Books, %L%
guicontrolget, sedit, 1:, sedit
scripture_T = %sedit%

; Start gdi+
If !pToken := Gdip_Startup()
{
   MsgBox, 48, gdiplus error!, Gdiplus failed to start. Please ensure you have gdiplu on your system
   ExitApp
}
OnExit, Exit

; Set the width and height we want as our drawing area, to draw everything in. This will be the dimensions of our bitmap
Width := 1810, Height := 1080

; Create a layered window (+E0x80000 : must be used for UpdateLayeredWindow to work!) that is always on top (+AlwaysOnTop), has no taskbar entry or caption
Gui, 2:  -Caption +E0x80000 +LastFound +OwnDialogs +Owner +AlwaysOnTop
; Show the window
Gui, 2: Show, NA
; Get a handle to this window we have created in order to update it later
hwnd1 := WinExist()
; Create a gdi bitmap with width and height of what we are going to draw into it. This is the entire drawing area for everything
hbm := CreateDIBSection(Width, Height)
; Get a device context compatible with the screen
hdc := CreateCompatibleDC()
; Select the bitmap into the device context
obm := SelectObject(hdc, hbm)
; Get a pointer to the graphics of the bitmap, for use with drawing functions
G := Gdip_GraphicsFromHDC(hdc)
; Set the smoothing mode to antialias = 4 to make shapes appear smother (only used for vector drawing and filling)
Gdip_SetSmoothingMode(G, 4)
; Create a partially transparent, black brush (ARGB = Transparency, red, green, blue) to draw a rounded rectangle with
pBrush := Gdip_BrushCreateSolid(0xaa000000)
; Fill the graphics of the bitmap with a rounded rectangle using the brush created
; Filling the entire graphics - from coordinates (0, 0) the entire width and height
; The last parameter (20) is the radius of the circles used for the rounded corners
Gdip_FillRoundedRectangle(G, pBrush, 0, 0, Width, Height, 20)
; Delete the brush as it is no longer needed and wastes memory
Gdip_DeleteBrush(pBrush)
; We can specify the font to use. Here we use Arial as most systems should have this installed
Font = Arial
; Next we can check that the user actually has the font that we wish them to use
; If they do not then we can do something about it. I choose to give a wraning and exit!
If !hFamily := Gdip_FontFamilyCreate(Font)
{
   MsgBox, 48, Font error!, The font you have specified does not exist on the system
   ExitApp
}
; Delete font family as we now know the font does exist
Gdip_DeleteFontFamily(hFamily)
Options = x10p y5p w80p Center cbbffffff r4 s70 
Gdip_TextToGraphics(G,book_v " " chap_v "`n`n" Sedit, Options, Font, Width, Height)
; Update the specified window we have created (hwnd1) with a handle to our bitmap (hdc), specifying the x,y,w,h we want it positioned on our screen
; With some simple math we can place the gui in the centre of our primary monitor horizontally and vertically at the specified heigth and width
UpdateLayeredWindow(hwnd1, hdc, 1024, 0, 1810, 1080)
; Select the object back into the hdc
SelectObject(hdc, obm)
; Now the bitmap may be deleted
DeleteObject(hbm)
; Also the device context related to the bitmap may be deleted
DeleteDC(hdc)
; The graphics may now be deleted
Gdip_DeleteGraphics(G)
gosub, gogui1
}
return

loadfunc()
{
IFExist, Listboxtxt.txt
      FileDelete, Listboxtxt.txt
Loop{  ;load loop
Savenumber = Save%a_index%
iniread, ini_r, options.ini, %Savenumber%, saveslot
ifinstring, ini_r, ERROR
   break
FileAppend, %ini_r%|`n, Listboxtxt.txt
}

}


guiclose:
Exit:
Gdip_Shutdown(pToken) ;gdi+ may now be shutdown on exiting the program
ExitApp